package com.umer.pinban;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Window;
import android.view.WindowManager;
import androidx.appcompat.app.AppCompatActivity;
import com.common.bean.UserInfo;
import com.common.db.UserDao;
import com.umer.pinban.user.LoginActivity;
import com.umer.pinban.user.UserLoginActivity;

public class StartActivity extends AppCompatActivity {

    private Handler handler;
    private UserDao mUserDao;
    private UserInfo mUserInfo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        mUserDao = new UserDao(this);
        handler = new Handler(new Handler.Callback(){
            @Override
            public boolean handleMessage(Message msg) {
                mUserInfo = mUserDao.query();
                if(mUserInfo!=null ){
                    AppHolder.getInstance().setUserInfo(mUserInfo);
                    Intent intent = new Intent(StartActivity.this, HomeActivity.class);
                    startActivity(intent);
                    finish();
                }else{
                    Intent intent = new Intent(StartActivity.this, LoginActivity.class);
                    startActivity(intent);
                    finish();
                }
                return true;
            }
        });
        handler.sendEmptyMessageDelayed(1,1000);
    }
}